//
//  RegisterRequest.m
//  Cbchot
//
//  Created by wangyue on 15/12/15.
//  Copyright © 2015年 王越. All rights reserved.
//

#import "RegisterRequest.h"
#import "UserInfo.h"
#import "iTools.h"

@interface RegisterRequest()<RequestBaseDelegate>

@property (nonatomic ,strong) UserInfo *userInfo;

@end

@implementation RegisterRequest

/**
 *  发起联网
 *
 */
-(void)startRequest:(CAll_BACK) sucuessBack fail:(CAll_BACK) failBack
{
    self.successBack = sucuessBack;
    self.failBack = failBack;
    
    NSString* url = [NSString stringWithFormat:@"%@/api/register_account/",[iTools ServerHost]];
    
    [self doPostRequest:url PostBody:nil Delegate:self];
}
//解析用户信息
-(void)parserData:(NSDictionary *)dic{
    if (self.responseCode == SUCCESS_OPERATION) {
        NSDictionary* user = [dic valueForKey:@"user"];
        _userInfo = [[UserInfo alloc]init];
        _userInfo.birthday = [user valueForKey:@"birthday"];
        _userInfo.userHeadicon = [user valueForKey:@"headPhoto"];
        _userInfo.level = [[user valueForKey:@"level"]intValue];
        _userInfo.mobile = [user valueForKey:@"mobile"];
        _userInfo.nickname = [user valueForKey:@"nickname"];
        _userInfo.password = [user valueForKey:@"password"];
        _userInfo.points = [[user valueForKey:@"points"]intValue];
        _userInfo.sex = [user valueForKey:@"sex"];
        _userInfo.thirdBundling = [user valueForKey:@"thirdBinding"];
        _userInfo.username = [user valueForKey:@"username"];
    }
}

/*联网解析完成*/
- (void)requestSuccess:(NSString*)message
{
    if(self.successBack){
        self.successBack(self.userInfo);
    }
}

/*联网失败*/
- (void)requestFailed:(NSString *)errorMessage
{
    if(self.failBack){
        self.failBack(errorMessage);
    }
}

@end
